<template>
  <div class="maintain_instrument">
    <el-dialog
      title="仪器保养"
      :visible.sync="dialogVisible"
      width="400px"
      v-dialogDrag
      :close-on-click-modal="false"
      customClass="mes_dialog">
      <div class="set_wrapper">
        <div class="set_item">
          <div class="set_label"><span class="import_required">*</span>保养项目:</div>
          <div class="set_cont">
            <el-select placeholder="请选择保养项目" v-model="maintainProjectID" size="small">
              <el-option
                v-for="item in MaintainPorject"
                :key="item.id"
                :label="item.label"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="set_item">
          <div class="set_label"><span class="import_required">*</span>保养人:</div>
          <div class="set_cont">
            <el-select filterable
                       placeholder="请选择保养人"
                       v-model="maintainEmployeeID" size="small">
              <el-option
                v-for="item in staffList"
                :key="item.ID"
                :label="item.NAME"
                :value="item.ID">
              </el-option>
            </el-select>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer mes_btn">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'MaintainDevice',
  props: {
    MaintainPorject: Array, // 保养项目列表
    staffList: Array, // 人员列表
  },
  data() {
    return {
      dialogVisible: false, // 是否显示
      maintainProjectID: '', // 保养项目ID
      maintainEmployeeID: '', // 保养人员ID
    }
  },
  methods: {
    // 打开，并清空
    openDialog() {
      this.maintainProjectID = ''
      this.maintainEmployeeID = ''
      this.dialogVisible = true
    },
    // 提交
    submit() {
      if (!this.maintainProjectID) {
        this.$message({
          type: 'error',
          message: '请选择保养项目！',
          duration: 1500,
          center: true
        })
      } else if (!this.maintainEmployeeID) {
        this.$message({
          type: 'error',
          message: '请选择保养人！',
          duration: 1500,
          center: true
        })
      } else {
        this.$emit('success', {
          maintainProjectID: this.maintainProjectID,
          maintainEmployeeID: this.maintainEmployeeID
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .maintain_instrument{
    .set_item{
      display: flex;
      align-items: center;
      &:first-child{
        padding-bottom: 10px;
      }
      .set_label{
        flex: 0 0 80px;
        text-align: right;
        padding-right: 10px;
      }
    }
  }
</style>
